package com.coinworld.utils;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/**
 * @description
 * @author:
 * @create: 2019-08-08 18:28
 **/
@Slf4j
public class CloudClassUtils {


    /**
     * HTTP 请求处理
     */
    public static JsonObject apiRequest(String url, HttpEntity reqEntity) throws Exception {
        String res = null;
        try {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(reqEntity);
            HttpClient httpClient = HttpClients.createDefault();
            HttpEntity httpEntity = httpClient.execute(httpPost).getEntity();
            res = EntityUtils.toString(httpEntity);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("人脸识别系统错误");
        }
        JsonObject resData = new JsonParser().parse(res).getAsJsonObject();
        System.out.println(String.format("result:%s", res));
        return resData;
    }

}
